# encoding: utf-8
# 项目名称： 常用设计模式
# @File  : 009-桥模式.py
# @Author: sun hao
# @Desc : 
# @Date  :   19:53 2024/10/29
from abc import ABCMeta, abstractmethod


class Shape(metaclass=ABCMeta):
    def __init__(self, color):
        self.color = color

    @abstractmethod
    def draw(self):
        pass


class Color(metaclass=ABCMeta):
    @abstractmethod
    def paint(self, shape):
        pass


class Rectangle(Shape):
    name = "长方形"

    def draw(self):
        self.color.paint(self)


class Circle(Shape):
    name = "圆形"

    def draw(self):
        self.color.paint(self)


# 具体的颜色类
class Red(Color):
    def paint(self, shape1):
        print(f"绘制 {shape1.name}，颜色为红色")


class Blue(Color):
    def paint(self, shape1):
        print(f"绘制 {shape1.name}，颜色为蓝色")


# 创建形状对象并设置颜色
red_rectangle = Rectangle(Red())
blue_circle = Circle(Blue())

# 绘制形状
red_rectangle.draw()  # 输出: 绘制 长方形，颜色为红色
blue_circle.draw()  # 输出: 绘制 圆形，颜色为蓝色
